package com.sunny.ynhz.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.sunny.ynhz.R;
import com.sunny.ynhz.utils.DensityUtil;

import java.util.List;

/**
 * Created by huhuan123 on 2018/6/1.
 */

public class ProgressProblemAdapter extends RecyclerView.Adapter<ProgressProblemAdapter.ViewHolder> {
    Context context;
    List<String> mlist;

    public ProgressProblemAdapter(Context context, List<String> mlist) {
        this.context = context;
        this.mlist = mlist;
    }

    @Override
    public ProgressProblemAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {

        return new ViewHolder(LayoutInflater.from(context).inflate(R.layout.item_progress_problem, parent, false));
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        if (position == 0) {
            holder.tv_progress_name.setText("动员组织");
        } else if (position == 1) {
            holder.tv_progress_name.setText("摸排调查");
        } else if (position == 2) {
            holder.tv_progress_name.setText("五整治活动");
        } else if (position == 3) {
            holder.tv_progress_name.setText("宣传教育活动");
        } else if (position == 4) {
            holder.tv_progress_name.setText("量化考核");
        } else if (position == 5) {
            holder.tv_progress_name.setText("基本改善目标");
        } else if (position == 6) {
            holder.tv_progress_name.setText("总体进度");
        }
        String progressValue = mlist.get(position);
        double v = Double.parseDouble(progressValue) / 100f * DensityUtil.dip2px(context, 200);
        ViewGroup.LayoutParams layoutParams = holder.ll_progress.getLayoutParams();
        layoutParams.width = (int) v;
        holder.ll_progress.setLayoutParams(layoutParams);
        holder.tv_progress_value.setText(progressValue+"%");


    }

    @Override
    public int getItemCount() {
        return 7;
    }

    class ViewHolder extends RecyclerView.ViewHolder {

        TextView tv_progress_name;
        LinearLayout ll_progress;
        TextView tv_progress_value;

        //在布局中找到所含有的UI组件
        public ViewHolder(View itemView) {
            super(itemView);
            tv_progress_name = itemView.findViewById(R.id.tv_progress_name);
            ll_progress = itemView.findViewById(R.id.ll_progress);
            tv_progress_value = itemView.findViewById(R.id.tv_progress_value);

        }
    }
}
